#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for(int i = (a);i <= (b);++i)
#define per(i,a,b) for(int i = (a);i >= (b);--i) 
#define mkp std::make_pair
typedef long long ll;
typedef unsigned long long ull;
using std::string;using std::cin;using std::cout;
inline bool cmp(int x,int y){return x < y;}
/* -fsanitize=undefined  */
const int N = 1e7+9;
const int inf = 1e9+9;
const double eps = 1e-7;
int _,n,m,a[2*N],u,v,cnt;
bool flag[2*N];
int head[2*N],next[2*N],ver[2*N],tot;
ll ans,edge[2*N],w;
inline void link(int x,int y){ver[++tot] = y , edge[tot] = w , next[tot] = head[x] , head[x] = tot;}
std::priority_queue< std::pair<ll,int> > q;

inline void solve(){
    while(q.size()) q.pop();
    flag[1] = true , ++cnt;
    for(int i = head[1];i;i = next[i]) q.push( mkp(-edge[i],ver[i]) );
    while(q.size()){
        int now = q.top().second;
        ll tmp = -q.top().first;
        q.pop();
        if( flag[now] ) continue;
        ans += tmp , flag[now] = true , ++cnt;
        if(cnt == n) break;
        for(int i = head[now];i;i = next[i]){
            if(flag[ ver[i] ]) continue;
            q.push( mkp(-edge[i],ver[i]) );
        }
    }
    if(cnt == n){
        flag[0] = true;
        return;
    } else {
        flag[0] = false;
        return;
    }
}

int main(){
    std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef LOCAL //  -DLOCAL
        freopen("in.in", "r", stdin);
    #endif
    cin >> n >> m;
    rep(i,1,m){
        cin >> u >> v >> w;
        link(u,v) , link(v,u);
    }
    solve();
    if(flag[0]) cout << ans << "\n";
    else cout << "orz\n"; 
    return 0;
}